//                        date: [[20120731120204]]
//                        Author: Ahmed Fathi Hamouda Abd El Hafez
using System;
using System.ComponentModel;
using System.Reflection;
using System.Data;
using System.Diagnostics;
using CustomersSuppliersDataLayer;
using System.Collections.Generic;


namespace CustomersSuppliersBusinessLayer
{
    /// <summary>
    ///  Business Object OF Table WorkersAttachments
    /// </summary>

    [Serializable]
    public partial class BLWorkersAttachment : INotifyPropertyChanged
    {
        #region Fields

        protected DLWorkersAttachment f_DLWorkersAttachment = new DLWorkersAttachment();

        protected Exception f_Error = null;

        protected BusinessObjectState f_State = BusinessObjectState.Created;

        protected Dictionary<string, object> extendedProperties = new Dictionary<string, object>();

        protected Dictionary<string, BLWorkersAttachment> RestorePoints = new Dictionary<string, BLWorkersAttachment>();

        #endregion

        #region constructors

        /// <summary>
        ///  initialize new insance from BLWorkersAttachment with no values ( all properties are set to null)
        /// </summary>
        public BLWorkersAttachment()
        {

        }


        /// <summary>
        ///  initialize new insance from BLWorkersAttachment with DLWorkersAttachment
        /// </summary>
        internal BLWorkersAttachment(DLWorkersAttachment DLWorkersAttachment, BusinessObjectState state)
        {
            this.f_DLWorkersAttachment = DLWorkersAttachment;
            this.f_State = state;
            this.f_Error = DLWorkersAttachment.Error;
        }

        /// <summary>
        ///  initialize new insance from BLWorkersAttachment.
        /// </summary>
        public BLWorkersAttachment(
        int? WorkerAttachment_RowNumber,  
        Guid? WorkerAttachment_ID,  
        Guid? Worker_ID,  
        string File_DisplayName,  
        string File_Path,  
        byte? Is_Encrypted,  
        byte[] File_Bytes,  
        string File_Notes,  
        string File_Search,  
        Guid? Mime_ID,  
        byte[] WorkerAttachment_TimeStamp
)
            : this()
        {
            this.WorkerAttachment_RowNumber = WorkerAttachment_RowNumber;
            this.WorkerAttachment_ID = WorkerAttachment_ID;
            this.Worker_ID = Worker_ID;
            this.File_DisplayName = File_DisplayName;
            this.File_Path = File_Path;
            this.Is_Encrypted = Is_Encrypted;
            this.File_Bytes = File_Bytes;
            this.File_Notes = File_Notes;
            this.File_Search = File_Search;
            this.Mime_ID = Mime_ID;
            this.WorkerAttachment_TimeStamp = WorkerAttachment_TimeStamp;
        }


        /// <summary>
        ///  initialize new insance from BLWorkersAttachment.
        /// </summary>
        public BLWorkersAttachment(
        Guid? WorkerAttachment_ID
        )
            : this()
        {
            this.WorkerAttachment_ID = WorkerAttachment_ID;
            }

        #endregion

        #region properties
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public int? WorkerAttachment_RowNumber
        {
            get
            {
                return this.DLWorkersAttachment.WorkerAttachment_RowNumber;
            }
            set
            {
                if (this.WorkerAttachment_RowNumber != value)
                {
                    this.DLWorkersAttachment.WorkerAttachment_RowNumber = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.WorkerAttachment_RowNumber);
                }
            }
        }
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public Guid? WorkerAttachment_ID
        {
            get
            {
                return this.DLWorkersAttachment.WorkerAttachment_ID;
            }
            set
            {
                if (this.WorkerAttachment_ID != value)
                {
                    this.DLWorkersAttachment.WorkerAttachment_ID = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.WorkerAttachment_ID);
                }
            }
        }
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public Guid? Worker_ID
        {
            get
            {
                return this.DLWorkersAttachment.Worker_ID;
            }
            set
            {
                if (this.Worker_ID != value)
                {
                    this.DLWorkersAttachment.Worker_ID = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.Worker_ID);
                }
            }
        }
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public string File_DisplayName
        {
            get
            {
                return this.DLWorkersAttachment.File_DisplayName;
            }
            set
            {
                if (this.File_DisplayName != value)
                {
                    this.DLWorkersAttachment.File_DisplayName = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.File_DisplayName);
                }
            }
        }
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public string File_Path
        {
            get
            {
                return this.DLWorkersAttachment.File_Path;
            }
            set
            {
                if (this.File_Path != value)
                {
                    this.DLWorkersAttachment.File_Path = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.File_Path);
                }
            }
        }
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public byte? Is_Encrypted
        {
            get
            {
                return this.DLWorkersAttachment.Is_Encrypted;
            }
            set
            {
                if (this.Is_Encrypted != value)
                {
                    this.DLWorkersAttachment.Is_Encrypted = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.Is_Encrypted);
                }
            }
        }
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public byte[] File_Bytes
        {
            get
            {
                return this.DLWorkersAttachment.File_Bytes;
            }
            set
            {
                if (this.File_Bytes != value)
                {
                    this.DLWorkersAttachment.File_Bytes = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.File_Bytes);
                }
            }
        }
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public string File_Notes
        {
            get
            {
                return this.DLWorkersAttachment.File_Notes;
            }
            set
            {
                if (this.File_Notes != value)
                {
                    this.DLWorkersAttachment.File_Notes = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.File_Notes);
                }
            }
        }
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public string File_Search
        {
            get
            {
                return this.DLWorkersAttachment.File_Search;
            }
            set
            {
                if (this.File_Search != value)
                {
                    this.DLWorkersAttachment.File_Search = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.File_Search);
                }
            }
        }
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public Guid? Mime_ID
        {
            get
            {
                return this.DLWorkersAttachment.Mime_ID;
            }
            set
            {
                if (this.Mime_ID != value)
                {
                    this.DLWorkersAttachment.Mime_ID = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.Mime_ID);
                }
            }
        }
        /// <summary>
        /// Gets or sets the _ColumName_ value.
        /// </summary>
        public byte[] WorkerAttachment_TimeStamp
        {
            get
            {
                return this.DLWorkersAttachment.WorkerAttachment_TimeStamp;
            }
            set
            {
                if (this.WorkerAttachment_TimeStamp != value)
                {
                    this.DLWorkersAttachment.WorkerAttachment_TimeStamp = value;
                    this.OnPropertyChanged(BLWorkersAttachment.PropertiesNames.WorkerAttachment_TimeStamp);
                }
            }
        }

        /// <summary>
        ///  get the data layer object 
        /// </summary>
        internal DLWorkersAttachment DLWorkersAttachment
        {
            get
            {
                return this.f_DLWorkersAttachment;
            }
        }

        /// <summary>
        /// get the error ocured after insert or update or delete or load
        /// </summary>
        public Exception Error
        {
            get { return this.f_DLWorkersAttachment.Error; }
        }

        /// <summary>
        /// gets the state of this object 
        /// </summary>
        public BusinessObjectState State
        {
            get
            {
                return this.f_State;
            }
        }

        /// <summary>
        ///  Indexer to access extended Properties
        /// </summary>
        public object this[string PropertyName]
        {
            get
            {
                return this.GetType().GetProperty(PropertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).GetValue(this, null);
            }
            set
            {
                this.GetType().GetProperty(PropertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).SetValue(this, value, null);
            }
        }

        /// <summary>
        ///  filter used for collection operations
        /// </summary>
        public List<DataFilter> Filters
        {
            get
            {
                return this.f_DLWorkersAttachment.Filters;
            }
        }


        /// <summary>
        /// sorts used for collection operations
        /// </summary>
        public List<DataSort> Sorts
        {
            get
            {
                return this.f_DLWorkersAttachment.Sorts;
            }
        }
        #endregion

        #region methods


        /// <summary>
        /// Insert the object in the dataBase
        /// </summary>
        public virtual int Insert(string[] properties, string[] autoDateProperties)
        {
            int count = 0;
            CancelEventArgs e = new CancelEventArgs(false);
            BLWorkersAttachment.ONBeforeInsertGlobal(this, e);
            if (!e.Cancel)
            {
                this.ONBeforeInsert(e);
                if (!e.Cancel)
                {
                    count = this.f_DLWorkersAttachment.Insert(properties, autoDateProperties);
                    this.f_Error = this.f_DLWorkersAttachment.Error;
                    BLWorkersAttachment.ONAfterInsertGlobal(this, this.f_Error);
                    this.ONAfterInsert();
                }
                else
                {
                    this.f_Error = new Exception("Action was Canceled");
                }
            }
            else
            {
                this.f_Error = new Exception("Action was Canceled");
            }
            if (this.f_Error == null)
            {
                this.f_State = BusinessObjectState.Loaded;
            }
            return count;
        }
        /// <summary>
        /// Insert the object in the dataBase using settings
        /// </summary>
        public virtual int Insert(string[] properties, string[] autoDateProperties, Settings setting)
        {
            int count = 0;
            CancelEventArgs e = new CancelEventArgs(false);
            BLWorkersAttachment.ONBeforeInsertGlobal(this, e);
            if (!e.Cancel)
            {
                this.ONBeforeInsert(e);
                if (!e.Cancel)
                {
                    count = this.f_DLWorkersAttachment.Insert(properties, autoDateProperties, setting);
                    this.f_Error = this.DLWorkersAttachment.Error;
                    BLWorkersAttachment.ONAfterInsertGlobal(this, this.f_Error);
                    this.ONAfterInsert();
                }
                else
                {
                    this.f_Error = new Exception("Action was Canceled");
                }
            }
            else
            {
                this.f_Error = new Exception("Action was Canceled");
            }
            if (this.f_Error == null)
            {
                this.f_State = BusinessObjectState.Loaded;
            }
            return count;

        }


        /// <summary>
        ///Update the object in the dataBase
        /// <summary>
        internal virtual int Update(string[] properties, string[] autoDateProperties)
        {
            int count = 0;
            CancelEventArgs e = new CancelEventArgs(false);
            BLWorkersAttachment.ONBeforeUpdateGlobal(this, e);
            if (!e.Cancel)
            {
                this.ONBeforeUpdate(e);
                if (!e.Cancel)
                {
                    count = this.f_DLWorkersAttachment.Update(properties, autoDateProperties);
                    this.f_Error = this.DLWorkersAttachment.Error;
                    BLWorkersAttachment.ONAfterUpdateGlobal(this, this.f_Error);
                    this.ONAfterUpdate();
                }
                else
                {
                    this.f_Error = new Exception("Action was Canceled");
                }
            }
            else
            {
                this.f_Error = new Exception("Action was Canceled");
            }
            if (this.f_Error == null)
            {
                this.f_State = BusinessObjectState.Loaded;
            }
            return count;
        }
        /// <summary>
        ///Update the object in the dataBase using settings
        /// <summary>
        internal virtual int Update(string[] properties, string[] autoDateProperties, Settings setting)
        {
            int count = 0;
            CancelEventArgs e = new CancelEventArgs(false);
            BLWorkersAttachment.ONBeforeUpdateGlobal(this, e);
            if (!e.Cancel)
            {
                this.ONBeforeUpdate(e);
                if (!e.Cancel)
                {
                    count = this.f_DLWorkersAttachment.Update(properties, autoDateProperties, setting);
                    this.f_Error = this.DLWorkersAttachment.Error;
                    BLWorkersAttachment.ONAfterUpdateGlobal(this, this.f_Error);
                    this.ONAfterUpdate();
                }
                else
                {
                    this.f_Error = new Exception("Action was Canceled");
                }
            }
            else
            {
                this.f_Error = new Exception("Action was Canceled");
            }
            if (this.f_Error == null)
            {
                this.f_State = BusinessObjectState.Loaded;
            }
            return count;
        }
        /// <summary>
        /// Update by some properties 
        /// </summary>
        internal virtual int UpdateByProperties(string[] properties, string[] autoDateProperties, string[] filterProperties)
        {
            this.Filters.Clear();
            if (filterProperties.Length > 0)
            {
                for (int i = 0; i < filterProperties.Length; i++)
                {
                    Type t=this.GetType().GetProperty(filterProperties[i], BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).PropertyType;
                    CustomersSuppliersDataLayer.DataFilter filter = new DataFilter(LogicalOperators.And, filterProperties[i], FilterOperators.Equal, this[filterProperties[i]], t);
                    this.Filters.Add(filter);
                }
            }
            return this.Update(properties, autoDateProperties);
        }
        /// <summary>
        /// Update by some properties using settings
        /// </summary>
        internal virtual int UpdateByProperties(string[] properties, string[] autoDateProperties, string[] filterProperties, Settings setting)
        {
            this.Filters.Clear();
            if (filterProperties.Length > 0)
            {
                for (int i = 0; i < filterProperties.Length; i++)
                {
                    Type t = this.GetType().GetProperty(filterProperties[i], BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).PropertyType;
                    CustomersSuppliersDataLayer.DataFilter filter = new DataFilter(LogicalOperators.And, filterProperties[i], FilterOperators.Equal, this[filterProperties[i]],t);
                    this.Filters.Add(filter);
                }
            }
            return this.Update(properties, autoDateProperties, setting);
        }
        /// <summary>
        /// Update by Identifiers only
        /// </summary>
        public virtual int UpdateByIdentifiers(string[] properties, string[] autoDateProperties)
        {
            return this.UpdateByProperties(properties, autoDateProperties, BLWorkersAttachment.PropertiesNames.Identifiers);
        }
        /// <summary>
        /// Update by Identifiers only using settings
        /// </summary>
        public virtual int UpdateByIdentifiers(string[] properties, string[] autoDateProperties, Settings setting)
        {
            return this.UpdateByProperties(properties, autoDateProperties, BLWorkersAttachment.PropertiesNames.Identifiers, setting);
        }




        /// <summary>
        ///InsertORUpdate the object in the dataBase
        /// <summary>
        internal virtual int InsertORUpdate(string[] propertiesInsert, string[] propertiesUpdate, string[] autoDateInsert, string[] autoDateUpadte, ref bool inserted)
        {
            int count = 0;
            CancelEventArgs e = new CancelEventArgs(false);
            BLWorkersAttachment.ONBeforeInsert_UpdateGlobal(this, e);
            if (!e.Cancel)
            {
                this.ONBeforeInsert_Update(e);
                if (!e.Cancel)
                {
                    count = this.f_DLWorkersAttachment.Insert_Update(propertiesInsert, propertiesUpdate, autoDateInsert, autoDateUpadte, ref inserted);
                    this.f_Error = this.f_DLWorkersAttachment.Error;
                    if (inserted)
                    {
                        BLWorkersAttachment.ONAfterInsertGlobal(this, this.f_Error);
                        this.ONAfterInsert();
                    }
                    else
                    {
                        BLWorkersAttachment.ONAfterUpdateGlobal(this, this.f_Error);
                        this.ONAfterUpdate();
                    }
                }
                else
                {
                    this.f_Error = new Exception("Action was Canceled");
                }
            }
            else
            {
                this.f_Error = new Exception("Action was Canceled");
            }
            if (this.f_Error == null)
            {
                this.f_State = BusinessObjectState.Loaded;
            }
            return count;
        }
        /// <summary>
        ///InsertORUpdate the object in the dataBase using settings
        /// <summary>
        internal virtual int InsertORUpdate(string[] propertiesInsert, string[] propertiesUpdate, string[] autoDateInsert, string[] autoDateUpadte, ref bool inserted, Settings setting)
        {
            int count = 0;
            CancelEventArgs e = new CancelEventArgs(false);
            BLWorkersAttachment.ONBeforeInsert_UpdateGlobal(this, e);
            if (!e.Cancel)
            {
                this.ONBeforeInsert_Update(e);
                if (!e.Cancel)
                {
                    count = this.f_DLWorkersAttachment.Insert_Update(propertiesInsert, propertiesUpdate, autoDateInsert, autoDateUpadte, ref inserted, setting);
                    this.f_Error = this.f_DLWorkersAttachment.Error;
                    if (inserted)
                    {
                        BLWorkersAttachment.ONAfterInsertGlobal(this, this.f_Error);
                        this.ONAfterInsert();
                    }
                    else
                    {
                        BLWorkersAttachment.ONAfterUpdateGlobal(this, this.f_Error);
                        this.ONAfterUpdate();
                    }
                }
                else
                {
                    this.f_Error = new Exception("Action was Canceled");
                }
            }
            else
            {
                this.f_Error = new Exception("Action was Canceled");
            }
            if (this.f_Error == null)
            {
                this.f_State = BusinessObjectState.Loaded;
            }
            return count;
        }
        /// <summary>
        /// InsertORUpdate by some properties 
        /// </summary>
        internal virtual int InsertORUpdateByProperties(string[] propertiesInsert, string[] propertiesUpdate, string[] autoDateInsert, string[] autoDateUpadte, string[] filterProperties, ref bool inserted)
        {
            this.Filters.Clear();
            if (filterProperties.Length > 0)
            {
                for (int i = 0; i < filterProperties.Length; i++)
                {
                    Type t = this.GetType().GetProperty(filterProperties[i], BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).PropertyType;
                    CustomersSuppliersDataLayer.DataFilter filter = new DataFilter(LogicalOperators.And, filterProperties[i], FilterOperators.Equal, this[filterProperties[i]],t);
                    this.Filters.Add(filter);
                }
            }
            return this.InsertORUpdate(propertiesInsert, propertiesUpdate, autoDateInsert, autoDateUpadte, ref inserted);
        }
        /// <summary>
        /// InsertORUpdate by some properties using settings
        /// </summary>
        internal virtual int InsertORUpdateByProperties(string[] propertiesInsert, string[] propertiesUpdate, string[] autoDateInsert, string[] autoDateUpadte, string[] filterProperties, ref bool inserted, Settings setting)
        {
            this.Filters.Clear();
            if (filterProperties.Length > 0)
            {
                for (int i = 0; i < filterProperties.Length; i++)
                {
                    Type t = this.GetType().GetProperty(filterProperties[i], BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).PropertyType;
                    CustomersSuppliersDataLayer.DataFilter filter = new DataFilter(LogicalOperators.And, filterProperties[i], FilterOperators.Equal, this[filterProperties[i]],t);
                    this.Filters.Add(filter);
                }
            }
            return this.InsertORUpdate(propertiesInsert, propertiesUpdate, autoDateInsert, autoDateUpadte, ref inserted, setting);
        }
        /// <summary>
        /// InsertORUpdate by Identifiers only
        /// </summary>
        public virtual int InsertORUpdateByIdentifiers(string[] propertiesInsert, string[] propertiesUpdate, string[] autoDateInsert, string[] autoDateUpadte, ref bool inserted)
        {
            return this.InsertORUpdateByProperties(propertiesInsert, propertiesUpdate, autoDateInsert, autoDateUpadte, BLWorkersAttachment.PropertiesNames.Identifiers, ref inserted);
        }
        /// <summary>
        /// InsertORUpdate by Identifiers only using settings
        /// </summary>
        public virtual int InsertORUpdateByIdentifiers(string[] propertiesInsert, string[] propertiesUpdate, string[] autoDateInsert, string[] autoDateUpadte, ref bool inserted, Settings setting)
        {
            return this.InsertORUpdateByProperties(propertiesInsert, propertiesUpdate, autoDateInsert, autoDateUpadte, BLWorkersAttachment.PropertiesNames.Identifiers, ref inserted, setting);
        }



        /// <summary>
        ///delete the object from the dataBase
        /// <summary>
        internal virtual int Delete()
        {
            int count = 0;
            CancelEventArgs e = new CancelEventArgs(false);
            BLWorkersAttachment.ONBeforeDeleteGlobal(this, e);
            if (!e.Cancel)
            {
                this.ONBeforeDelete(e);
                if (!e.Cancel)
                {
                    count = this.f_DLWorkersAttachment.Delete();
                    this.f_Error = this.f_DLWorkersAttachment.Error;
                    BLWorkersAttachment.ONAfterDeleteGlobal(this, this.f_Error);
                    this.ONAfterDelete();
                }
                else
                {
                    this.f_Error = new Exception("Action was Canceled");
                }
            }
            else
            {
                this.f_Error = new Exception("Action was Canceled");
            }
            if (this.f_Error == null)
            {
                this.f_State = BusinessObjectState.CreatedModified;
            }
            return count;
        }
        /// <summary>
        ///delete the object from the dataBase using settings
        /// <summary>
        internal virtual int Delete(Settings setting)
        {
            int count = 0;
            CancelEventArgs e = new CancelEventArgs(false);
            BLWorkersAttachment.ONBeforeDeleteGlobal(this, e);
            if (!e.Cancel)
            {
                this.ONBeforeDelete(e);
                if (!e.Cancel)
                {
                    count = this.f_DLWorkersAttachment.Delete(setting);
                    this.f_Error = this.f_DLWorkersAttachment.Error;
                    BLWorkersAttachment.ONAfterDeleteGlobal(this, this.f_Error);
                    this.ONAfterDelete();
                }
                else
                {
                    this.f_Error = new Exception("Action was Canceled");
                }
            }
            else
            {
                this.f_Error = new Exception("Action was Canceled");
            }
            if (this.f_Error == null)
            {
                this.f_State = BusinessObjectState.CreatedModified;
            }
            return count;
        }
        /// <summary>
        /// Delete by some properties 
        /// </summary>
        internal virtual int DeleteByProperties(string[] filterProperties)
        {
            this.Filters.Clear();
            if (filterProperties.Length > 0)
            {
                for (int i = 0; i < filterProperties.Length; i++)
                {
                    Type t = this.GetType().GetProperty(filterProperties[i], BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).PropertyType;
                    CustomersSuppliersDataLayer.DataFilter filter = new DataFilter(LogicalOperators.And, filterProperties[i], FilterOperators.Equal, this[filterProperties[i]],t);
                    this.Filters.Add(filter);
                }
            }
            return this.Delete();
        }
        /// <summary>
        /// Delete by some properties using settings
        /// </summary>
        internal virtual int DeleteByProperties(string[] filterProperties, Settings setting)
        {
            this.Filters.Clear();
            if (filterProperties.Length > 0)
            {
                for (int i = 0; i < filterProperties.Length; i++)
                {
                    Type t = this.GetType().GetProperty(filterProperties[i], BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).PropertyType;
                    CustomersSuppliersDataLayer.DataFilter filter = new DataFilter(LogicalOperators.And, filterProperties[i], FilterOperators.Equal, this[filterProperties[i]], t);
                    this.Filters.Add(filter);
                }
            }
            return this.Delete(setting);
        }
        /// <summary>
        /// Delete by Identifiers only
        /// </summary>
        public virtual int DeleteByIdentifiers()
        {
            return this.DeleteByProperties(BLWorkersAttachment.PropertiesNames.Identifiers);
        }
        /// <summary>
        /// Delete by Identifiers only using settings
        /// </summary>
        public virtual int DeleteByIdentifiers(Settings setting)
        {
            return this.DeleteByProperties(BLWorkersAttachment.PropertiesNames.Identifiers, setting);
        }
        /// <summary>
        /// mark the object as deleted used in autosave to delete it
        /// </summary>
        public void MarkAsDeleted()
        {
            this.f_State = BusinessObjectState.MarkAsDeleted;
        }

        /// <summary>
        /// Default save object to dataBase of the object (return true if insert operation is done)
        /// </summary>
        public virtual bool DefaultSave(SaveType saveType)
        {
            if (saveType == SaveType.Insert)
            {
                this.Insert(BLWorkersAttachment.PropertiesNames.DefaultInsert, BLWorkersAttachment.PropertiesNames.AutoDateInsert);
                return true;
            }
            else if (saveType == SaveType.Update)
            {
                this.UpdateByIdentifiers(BLWorkersAttachment.PropertiesNames.DefaultUpdate, BLWorkersAttachment.PropertiesNames.AutoDateUpdate);
                return false;
            }
            else if (saveType == SaveType.Insert_Update)
            {
                bool inserted = false;
                this.InsertORUpdateByIdentifiers(BLWorkersAttachment.PropertiesNames.DefaultInsert, BLWorkersAttachment.PropertiesNames.DefaultUpdate, BLWorkersAttachment.PropertiesNames.AutoDateInsert, BLWorkersAttachment.PropertiesNames.AutoDateUpdate, ref inserted);
                return inserted;
            }
            else if (saveType == SaveType.Delete)
            {
                this.DeleteByIdentifiers();
                return false;
            }
            return false;
        }
        /// <summary>
        /// Default save object to dataBase of the object using setting (return true if insert operation is done)
        /// </summary>
        public virtual bool DefaultSave(SaveType saveType, Settings setting)
        {
            if (saveType == SaveType.Insert)
            {
                this.Insert(BLWorkersAttachment.PropertiesNames.DefaultInsert, BLWorkersAttachment.PropertiesNames.AutoDateInsert, setting);
                return true;
            }
            else if (saveType == SaveType.Update)
            {
                this.UpdateByIdentifiers(BLWorkersAttachment.PropertiesNames.DefaultUpdate, BLWorkersAttachment.PropertiesNames.AutoDateUpdate, setting);
                return false;
            }
            else if (saveType == SaveType.Insert_Update)
            {
                bool inserted = false;
                this.InsertORUpdateByIdentifiers(BLWorkersAttachment.PropertiesNames.DefaultInsert, BLWorkersAttachment.PropertiesNames.DefaultUpdate, BLWorkersAttachment.PropertiesNames.AutoDateInsert, BLWorkersAttachment.PropertiesNames.AutoDateUpdate, ref inserted, setting);
                return inserted;
            }
            else if (saveType == SaveType.Delete)
            {
                this.DeleteByIdentifiers(setting);
                return false;
            }
            return false;
        }


        /// <summary>
        /// auto save object to dataBase depends on state of the object 
        /// </summary>
        public virtual void AutoSave()
        {
            if (this.f_State == BusinessObjectState.Created || this.f_State == BusinessObjectState.CreatedModified)
            {
                this.Insert(BLWorkersAttachment.PropertiesNames.DefaultInsert, BLWorkersAttachment.PropertiesNames.AutoDateInsert);
            }
            else if (this.f_State == BusinessObjectState.loadedModified)
            {
                this.UpdateByIdentifiers(BLWorkersAttachment.PropertiesNames.DefaultUpdate, BLWorkersAttachment.PropertiesNames.AutoDateUpdate);
            }
            else if (this.f_State == BusinessObjectState.MarkAsDeleted)
            {
                this.DeleteByIdentifiers();
            }
        }
        /// <summary>
        /// auto save object to dataBase depends on state of the object using settings
        /// </summary>
        public virtual void AutoSave(Settings setting)
        {
            if (this.f_State == BusinessObjectState.Created || this.f_State == BusinessObjectState.CreatedModified)
            {
                this.Insert(BLWorkersAttachment.PropertiesNames.DefaultInsert, BLWorkersAttachment.PropertiesNames.AutoDateInsert, setting);
            }
            else if (this.f_State == BusinessObjectState.loadedModified)
            {
                this.UpdateByIdentifiers(BLWorkersAttachment.PropertiesNames.DefaultUpdate, BLWorkersAttachment.PropertiesNames.AutoDateUpdate, setting);
            }
            else if (this.f_State == BusinessObjectState.MarkAsDeleted)
            {
                this.DeleteByIdentifiers(setting);
            }
        }



        /// <summary>
        /// load data
        /// </summary>
        internal virtual void Load()
        {
            CancelEventArgs e = new CancelEventArgs(false);
            BLWorkersAttachment.ONBeforeLoadGlobal(this, e);
            if (!e.Cancel)
            {
                this.ONBeforeLoad(e);
                if (!e.Cancel)
                {
                    bool isLoaded = this.f_DLWorkersAttachment.LoadData();
                    this.f_Error = this.DLWorkersAttachment.Error;
                    if (this.f_Error == null && isLoaded)
                    {
                        this.f_State = BusinessObjectState.Loaded;
                        this.ONAfterLoad();
                        BLWorkersAttachment.ONAfterLoadGlobal(this, this.f_Error);
                    }
                }
                else
                {
                    this.f_Error = new Exception("Action was Canceled");
                }
            }
            else
            {
                this.f_Error = new Exception("Action was Canceled");
            }
        }
        /// <summary>
        /// load data using settins
        /// </summary>
        internal virtual void Load(Settings setting)
        {
            CancelEventArgs e = new CancelEventArgs(false);
            BLWorkersAttachment.ONBeforeLoadGlobal(this, e);
            if (!e.Cancel)
            {
                this.ONBeforeLoad(e);
                if (!e.Cancel)
                {
                    bool isLoaded = this.f_DLWorkersAttachment.LoadData(setting);
                    this.f_Error = this.DLWorkersAttachment.Error;
                    if (this.f_Error == null && isLoaded)
                    {
                        this.f_State = BusinessObjectState.Loaded;
                        this.ONAfterLoad();
                        BLWorkersAttachment.ONAfterLoadGlobal(this, this.f_Error);
                    }
                }
                else
                {
                    this.f_Error = new Exception("Action was Canceled");
                }
            }
            else
            {
                this.f_Error = new Exception("Action was Canceled");
            }
        }
        /// <summary>
        /// load by some properties 
        /// </summary>
        internal virtual void LoadByProperties(string[] filterProperties)
        {
            this.Filters.Clear();
            if (filterProperties.Length > 0)
            {
                for (int i = 0; i < filterProperties.Length; i++)
                {
                    Type t = this.GetType().GetProperty(filterProperties[i], BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).PropertyType;
                    CustomersSuppliersDataLayer.DataFilter filter = new DataFilter(LogicalOperators.And, filterProperties[i], FilterOperators.Equal, this[filterProperties[i]], t);
                    this.Filters.Add(filter);
                }
            }
            this.Load();
        }
        /// <summary>
        /// load by some properties using settings
        /// </summary>
        internal virtual void LoadByProperties(string[] filterProperties, Settings setting)
        {
            this.Filters.Clear();
            if (filterProperties.Length > 0)
            {
                for (int i = 0; i < filterProperties.Length; i++)
                {
                    Type t = this.GetType().GetProperty(filterProperties[i], BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).PropertyType;
                    CustomersSuppliersDataLayer.DataFilter filter = new DataFilter(LogicalOperators.And, filterProperties[i], FilterOperators.Equal, this[filterProperties[i]], t);
                    this.Filters.Add(filter);
                }
            }
            this.Load(setting);
        }
        /// <summary>
        /// load by Identifiers only
        /// </summary>
        public virtual void LoadByIdentifiers()
        {
            this.LoadByProperties(BLWorkersAttachment.PropertiesNames.Identifiers);
        }
        /// <summary>
        /// load by Identifiers only using settings
        /// </summary>
        public virtual void LoadByIdentifiers(Settings setting)
        {
            this.LoadByProperties(BLWorkersAttachment.PropertiesNames.Identifiers, setting);
        }
        /// <summary>
        /// test if the kes are the same in both objects
        /// </summary>
        public virtual bool IsIdentifiersEqual(BLWorkersAttachment otherItem)
        {
            bool iseqal = true;
            for (int i = 0; i < BLWorkersAttachment.PropertiesNames.Identifiers.Length; i++)
            {
                if (this[BLWorkersAttachment.PropertiesNames.Identifiers[i]] == null
                    || this[BLWorkersAttachment.PropertiesNames.Identifiers[i]] != otherItem[BLWorkersAttachment.PropertiesNames.Identifiers[i]])
                {
                    iseqal = false;
                }
            }
            return iseqal;
        }


        /// <summary>
        /// add filter used with collections operations
        /// </summary>
        public void AddFilter(LogicalOperators logicalOperator, string property, FilterOperators filterOperator, object value,Type t)
        {
            DataFilter filter = new DataFilter(logicalOperator, property, filterOperator, value, t);
            this.Filters.Add(filter);
        }
        /// <summary>
        /// add sort used with collections operations
        /// </summary>
        public void AddSort(string property, bool descending)
        {
            DataSort sort = new DataSort(property, descending);
            this.Sorts.Add(sort);
        }



        /// <summary>
        /// Export the object to other object (if no prperties is defined all properties is Exported)
        /// </summary>
        public void ExportTo(BLWorkersAttachment otherItem, string[] Properties)
        {
            for (int i = 0; i < Properties.Length; i++)
            {
                otherItem[Properties[i]] = this[Properties[i]];
            }
            otherItem.f_State = this.f_State;
        }
        /// <summary>
        /// Import the object to other object (if no prperties is defined all properties is Imported)
        /// </summary>
        public void ImportFrom(BLWorkersAttachment otherItem, string[] properties)
        {
            otherItem.ExportTo(this, properties);
        }


        /// <summary>
        /// store the object in named restore point
        /// </summary>
        public void SetRestorePoint(string RestorePointName)
        {
            BLWorkersAttachment otherItem = new BLWorkersAttachment();
            otherItem.ImportFrom(this, BLWorkersAttachment.PropertiesNames.All);
            otherItem.f_Error = this.f_Error;
            otherItem.extendedProperties = new Dictionary<string, object>(this.extendedProperties);
            this.RestorePoints.Add(RestorePointName.ToLower(), otherItem);
        }
        /// <summary>
        /// restore the object from named restore point
        /// </summary>
        public void RestoreFrom(string RestorePointName)
        {
            BLWorkersAttachment otherItem = this.RestorePoints[RestorePointName.ToLower()];
            this.ImportFrom(otherItem, BLWorkersAttachment.PropertiesNames.All);
            this.f_Error = otherItem.f_Error;
            this.extendedProperties = new Dictionary<string, object>(this.extendedProperties);
        }
        /// <summary>
        /// clear all restore popints
        /// </summary>
        public void ClearRestorePoints(string name)
        {
            this.RestorePoints.Clear();
        }

        #endregion

        #region Events
        public event PropertyChangedEventHandler PropertyChanged;

        public event CancelEventHandler BeforeLoad;
        public event CancelEventHandler BeforeInsert;
        public event CancelEventHandler BeforeUpdate;
        public event CancelEventHandler BeforeDelete;
        public event CancelEventHandler BeforeInsert_Update;
        public event EventHandler AfterLoad;
        public event EventHandler AfterInsert;
        public event EventHandler AfterUpdate;
        public event EventHandler AfterDelete;


        public static event CancelEventHandler BeforeLoadGlobal;
        public static event CancelEventHandler BeforeInsertGlobal;
        public static event CancelEventHandler BeforeUpdateGlobal;
        public static event CancelEventHandler BeforeDeleteGlobal;
        public static event CancelEventHandler BeforeInsert_UpdateGlobal;
        public static event EventHandler AfterLoadGlobal;
        public static event EventHandler AfterInsertGlobal;
        public static event EventHandler AfterUpdateGlobal;
        public static event EventHandler AfterDeleteGlobal;
        #endregion

        #region events raising
        /// <summary> 
        /// raise the event PropertyChanged
        /// </summary> 
        protected virtual void OnPropertyChanged(string name)
        {
            if (this.f_State == BusinessObjectState.Created)
            {
                this.f_State = BusinessObjectState.CreatedModified;
            }
            if (this.f_State == BusinessObjectState.Loaded)
            {
                this.f_State = BusinessObjectState.loadedModified;
            }

            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }

        /// <summary> 
        /// raise the event BeforeLoad
        /// </summary> 
        protected virtual void ONBeforeLoad(CancelEventArgs e)
        {
            if (this.BeforeLoad != null)
            {
                this.BeforeLoad(this, e);
            }
        }
        /// <summary> 
        /// raise the event BeforeInsert 
        /// </summary> 
        protected virtual void ONBeforeInsert(CancelEventArgs e)
        {
            if (this.BeforeInsert != null)
            {
                this.BeforeInsert(this, e);
            }
        }
        /// <summary> 
        /// raise the event BeforeUpdate 
        /// </summary> 
        protected virtual void ONBeforeUpdate(CancelEventArgs e)
        {
            if (this.BeforeUpdate != null)
            {
                this.BeforeUpdate(this, e);
            }
        }
        /// <summary> 
        /// raise the event BeforeDelete 
        /// </summary> 
        protected virtual void ONBeforeDelete(CancelEventArgs e)
        {
            if (this.BeforeDelete != null)
            {
                this.BeforeDelete(this, e);
            }
        }
        /// <summary> 
        /// raise the event BeforeInsert_Update 
        /// </summary> 
        protected virtual void ONBeforeInsert_Update(CancelEventArgs e)
        {
            if (this.BeforeInsert_Update != null)
            {
                this.BeforeInsert_Update(this, e);
            }
        }
        /// <summary> 
        /// raise the event BeforeLoad
        /// </summary> 
        protected virtual void ONAfterLoad()
        {
            if (this.AfterLoad != null)
            {
                this.AfterLoad(this, new EventArgs());
            }
        }
        /// <summary> 
        /// raise the event AfterInsert 
        /// </summary> 
        protected virtual void ONAfterInsert()
        {
            if (this.f_Error == null && this.AfterInsert != null)
            {
                this.AfterInsert(this, new EventArgs());
            }
        }
        /// <summary> 
        /// raise the event AfterUpdate 
        /// </summary> 
        protected virtual void ONAfterUpdate()
        {
            if (this.f_Error == null && this.AfterUpdate != null)
            {
                this.AfterUpdate(this, new EventArgs());
            }
        }
        /// <summary> 
        /// raise the event AfterDelete 
        /// </summary> 
        protected virtual void ONAfterDelete()
        {
            if (this.f_Error == null && this.AfterDelete != null)
            {
                this.AfterDelete(this, new EventArgs());
            }
        }


        /// <summary> 
        /// raise the event BeforeLoadGlobal  
        /// </summary> 
        protected static void ONBeforeLoadGlobal(BLWorkersAttachment sender, CancelEventArgs e)
        {
            if (BLWorkersAttachment.BeforeLoadGlobal != null)
            {
                BLWorkersAttachment.BeforeLoadGlobal(sender, e);
            }
        }
        /// <summary> 
        /// raise the event BeforeInsertGlobal  
        /// </summary> 
        protected static void ONBeforeInsertGlobal(BLWorkersAttachment sender, CancelEventArgs e)
        {
            if (BLWorkersAttachment.BeforeInsertGlobal != null)
            {
                BLWorkersAttachment.BeforeInsertGlobal(sender, e);
            }
        }
        /// <summary> 
        /// raise the event BeforeUpdateGlobal  
        /// </summary> 
        protected static void ONBeforeUpdateGlobal(BLWorkersAttachment sender, CancelEventArgs e)
        {
            if (BLWorkersAttachment.BeforeUpdateGlobal != null)
            {
                BLWorkersAttachment.BeforeUpdateGlobal(sender, e);
            }
        }
        /// <summary> 
        /// raise the event BeforeDeleteGlobal  
        /// </summary> 
        protected static void ONBeforeDeleteGlobal(BLWorkersAttachment sender, CancelEventArgs e)
        {
            if (BLWorkersAttachment.BeforeDeleteGlobal != null)
            {
                BLWorkersAttachment.BeforeDeleteGlobal(sender, e);
            }
        }
        /// <summary> 
        /// raise the event BeforeInsert_UpdateGlobal  
        /// </summary> 
        protected static void ONBeforeInsert_UpdateGlobal(BLWorkersAttachment sender, CancelEventArgs e)
        {
            if (BLWorkersAttachment.BeforeInsert_UpdateGlobal != null)
            {
                BLWorkersAttachment.BeforeInsert_UpdateGlobal(sender, e);
            }
        }
        /// <summary> 
        /// raise the event AfterLoadGlobal  
        /// </summary> 
        protected static void ONAfterLoadGlobal(BLWorkersAttachment sender, Exception error)
        {
            if (error == null && BLWorkersAttachment.AfterLoadGlobal != null)
            {
                BLWorkersAttachment.AfterLoadGlobal(sender, new EventArgs());
            }
        }
        /// <summary> 
        /// raise the event AfterInsertGlobal  
        /// </summary> 
        protected static void ONAfterInsertGlobal(BLWorkersAttachment sender, Exception error)
        {
            if (error == null && BLWorkersAttachment.AfterInsertGlobal != null)
            {
                BLWorkersAttachment.AfterInsertGlobal(sender, new EventArgs());
            }
        }
        /// <summary> 
        /// raise the event AfterUpdateGlobal  
        /// </summary> 
        protected static void ONAfterUpdateGlobal(BLWorkersAttachment sender, Exception error)
        {
            if (error == null && BLWorkersAttachment.AfterUpdateGlobal != null)
            {
                BLWorkersAttachment.AfterUpdateGlobal(sender, new EventArgs());
            }
        }
        /// <summary> 
        /// raise the event AfterDeleteGlobal  
        /// </summary> 
        protected static void ONAfterDeleteGlobal(BLWorkersAttachment sender, Exception error)
        {
            if (error == null && BLWorkersAttachment.AfterDeleteGlobal != null)
            {
                BLWorkersAttachment.AfterDeleteGlobal(sender, new EventArgs());
            }
        }

        #endregion

        #region propertiesNames
        /// <summary>
        /// contains properties names for the object (used in binding)
        /// </summary>
        public partial class PropertiesNames
        {
            private static string[] f_Identifiers = new string[]
            {
                BLWorkersAttachment.PropertiesNames.WorkerAttachment_ID
            };
            /// <summary>
            /// return identifirs properties names in the object
            /// </summary>
            public static string[] Identifiers
            {
                get
                {
                    return BLWorkersAttachment.PropertiesNames.f_Identifiers;
                }
            }

            private static string[] f_DefaultInsert = new string[]
            {
                BLWorkersAttachment.PropertiesNames.WorkerAttachment_ID, 
                
                BLWorkersAttachment.PropertiesNames.Worker_ID, 
                
                BLWorkersAttachment.PropertiesNames.File_DisplayName, 
                
                BLWorkersAttachment.PropertiesNames.File_Path, 
                
                BLWorkersAttachment.PropertiesNames.Is_Encrypted, 
                
                BLWorkersAttachment.PropertiesNames.File_Bytes, 
                
                BLWorkersAttachment.PropertiesNames.File_Notes, 
                
                BLWorkersAttachment.PropertiesNames.File_Search, 
                
                BLWorkersAttachment.PropertiesNames.Mime_ID
            };
            /// <summary>
            /// return default properties names for insert
            /// </summary>
            public static string[] DefaultInsert
            {
                get
                {
                    return BLWorkersAttachment.PropertiesNames.f_DefaultInsert;
                }
            }

            private static string[] f_AutoDateInsert = new string[]
            {
                
            };
            /// <summary>
            /// return AutoDate properties names for insert
            /// </summary>
            public static string[] AutoDateInsert
            {
                get
                {
                    return BLWorkersAttachment.PropertiesNames.f_AutoDateInsert;
                }
            }


            private static string[] f_DefaultUpdate = new string[]
            {
                BLWorkersAttachment.PropertiesNames.Worker_ID, 
                
                BLWorkersAttachment.PropertiesNames.File_DisplayName, 
                
                BLWorkersAttachment.PropertiesNames.File_Path, 
                
                BLWorkersAttachment.PropertiesNames.Is_Encrypted, 
                
                BLWorkersAttachment.PropertiesNames.File_Bytes, 
                
                BLWorkersAttachment.PropertiesNames.File_Notes, 
                
                BLWorkersAttachment.PropertiesNames.File_Search, 
                
                BLWorkersAttachment.PropertiesNames.Mime_ID
            };
            /// <summary>
            /// return default properties names for Update
            /// </summary>
            public static string[] DefaultUpdate
            {
                get
                {
                    return BLWorkersAttachment.PropertiesNames.f_DefaultUpdate;
                }
            }

            private static string[] f_AutoDateUpdate = new string[]
            {
                
            };
            /// <summary>
            /// return AutoDate properties names for Update
            /// </summary>
            public static string[] AutoDateUpdate
            {
                get
                {
                    return BLWorkersAttachment.PropertiesNames.f_AutoDateUpdate;
                }
            }


            private static string[] f_All = new string[]
            {
                BLWorkersAttachment.PropertiesNames.WorkerAttachment_RowNumber, 
                BLWorkersAttachment.PropertiesNames.WorkerAttachment_ID, 
                BLWorkersAttachment.PropertiesNames.Worker_ID, 
                BLWorkersAttachment.PropertiesNames.File_DisplayName, 
                BLWorkersAttachment.PropertiesNames.File_Path, 
                BLWorkersAttachment.PropertiesNames.Is_Encrypted, 
                BLWorkersAttachment.PropertiesNames.File_Bytes, 
                BLWorkersAttachment.PropertiesNames.File_Notes, 
                BLWorkersAttachment.PropertiesNames.File_Search, 
                BLWorkersAttachment.PropertiesNames.Mime_ID, 
                BLWorkersAttachment.PropertiesNames.WorkerAttachment_TimeStamp
            };
            /// <summary>
            /// return All properties names in the object
            /// </summary>
            public static string[] All
            {
                get
                {
                    return BLWorkersAttachment.PropertiesNames.f_All;
                }
            }


            public static string WorkerAttachment_RowNumber
            {
                get
                {
                    return "WorkerAttachment_RowNumber";
                }
            }
            public static string WorkerAttachment_ID
            {
                get
                {
                    return "WorkerAttachment_ID";
                }
            }
            public static string Worker_ID
            {
                get
                {
                    return "Worker_ID";
                }
            }
            public static string File_DisplayName
            {
                get
                {
                    return "File_DisplayName";
                }
            }
            public static string File_Path
            {
                get
                {
                    return "File_Path";
                }
            }
            public static string Is_Encrypted
            {
                get
                {
                    return "Is_Encrypted";
                }
            }
            public static string File_Bytes
            {
                get
                {
                    return "File_Bytes";
                }
            }
            public static string File_Notes
            {
                get
                {
                    return "File_Notes";
                }
            }
            public static string File_Search
            {
                get
                {
                    return "File_Search";
                }
            }
            public static string Mime_ID
            {
                get
                {
                    return "Mime_ID";
                }
            }
            public static string WorkerAttachment_TimeStamp
            {
                get
                {
                    return "WorkerAttachment_TimeStamp";
                }
            }

            //internal static object GetValue(BLWorkersAttachment obj, string Property)
            //{
            //    return typeof(BLWorkersAttachment).GetProperty(Property, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).GetValue(obj, null);
            //}
        }
        #endregion

    }
}
